package com.wei.czz.framework.store.controller;

import com.wei.czz.common.annotation.Resubmit;
import com.wei.czz.common.dto.store.audit.AccountAuditDetailDto;
import com.wei.czz.common.dto.store.audit.BossAuditDetailDto;
import com.wei.czz.common.dto.store.audit.StoreAuditDetailDto;
import com.wei.czz.common.enums.CommonEnum;
import com.wei.czz.common.vo.store.audit.AuditSaveVo;
import com.wei.czz.framework.store.manager.AuditManager;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.wei.czz.common.tool.Result;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-12-01 11:38:26
 * className: AuditStoreController
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("/audit-store")
@AllArgsConstructor
public class AuditStoreController {

    private static final Logger log = LoggerFactory.getLogger(AuditStoreController.class);

    private final AuditManager auditManager;

    /**
     * 保存商店审核接口
     * <p>
     * 此接口会校验是否重复提交
     * @param auditSaveVo 参数对象
     */
    @Resubmit(message = "商店审核")
    @RequestMapping("/save")
    public Result<Object> saveAuditStore(@Validated @RequestBody AuditSaveVo auditSaveVo) {
        log.info("开始保存商店审核业务。{}", auditSaveVo);

        if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())
                && StringUtils.isBlank(auditSaveVo.getAuditRemark())) {
            log.info("商店审核拒绝，审核回复为空");
            return Result.clientFail("商店审核拒绝，审核回复不能为空");
        }

        auditManager.saveAuditStore(auditSaveVo);

        log.info("保存商店审核业务结束");
        return Result.success();
    }

    /**
     * 保存商店账户审核接口
     * <p>
     * 此接口会校验是否重复提交
     * @param auditSaveVo 参数对象
     * @return 结果
     */
    @Resubmit(message = "商店账户审核")
    @PostMapping("/account/save")
    public Result<Object> saveAuditAccount(@Validated @RequestBody AuditSaveVo auditSaveVo) {
        log.info("开始保存商店账户审核业务。{}", auditSaveVo);

        if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())
                && StringUtils.isBlank(auditSaveVo.getAuditRemark())) {
            log.info("商店账户审核拒绝，审核回复为空");
            return Result.clientFail("商店账户审核拒绝，审核回复不能为空");
        }

        auditManager.saveAuditAccount(auditSaveVo);

        log.info("保存商店账户审核业务结束");
        return Result.success();
    }

    /**
     * 保存商店老板审核接口
     * <p>
     * 此接口会校验是否重复提交
     * @param auditSaveVo 参数对象
     * @return 结果
     */
    @Resubmit(message = "商店老板审核")
    @PostMapping("/boss/save")
    public Result<Object> saveAuditBoss(@Validated @RequestBody AuditSaveVo auditSaveVo) {
        log.info("开始保存商店老板审核业务。{}", auditSaveVo);

        if (CommonEnum.ONE.getValue().equals(auditSaveVo.getStatus())
                && StringUtils.isBlank(auditSaveVo.getAuditRemark())) {
            log.info("商店老板审核拒绝，审核回复为空");
            return Result.clientFail("商店老板审核拒绝，审核回复不能为空");
        }

        auditManager.saveAuditBoss(auditSaveVo);

        log.info("保存商店老板审核业务结束");
        return Result.success();
    }

    /**
     * 获取商店最新一条审核通过数据接口
     * @param businessId 商店主键
     * @return 结果
     */
    @GetMapping("/last/finish/detail")
    public Result<StoreAuditDetailDto> getStoreLastFinishDetail(@RequestParam("businessId") Long businessId) {
        log.info("开始获取商店审核对比数据业务。businessId={}", businessId);

        StoreAuditDetailDto storeLastFinishDetailDto = auditManager.getStoreLastFinishDetail(businessId);

        log.info("获取商店审核对比数据业务结束");
        return Result.success(storeLastFinishDetailDto);
    }

    /**
     * 获取商店审核数据接口
     * @param id 商店主键
     * @return 结果
     */
    @GetMapping("/audit/detail")
    public Result<StoreAuditDetailDto> getAuditStoreDetail(@RequestParam("id") Long id,
                                      @RequestParam("contrastStatus") Integer contrastStatus) {
        log.info("开始获取商店审核数据业务。id={}", id);

        StoreAuditDetailDto storeAuditDetailDto = auditManager.getAuditStoreDetail(id, contrastStatus);

        log.info("获取商店审核数据业务结束");
        return Result.success(storeAuditDetailDto);
    }

    /**
     * 获取商店账户审核数据接口
     * @param storeId 商店账户
     * @return 结果
     */
    @GetMapping("/account/detail")
    public Result<AccountAuditDetailDto> getAccountAuditDetail(@RequestParam("storeId") Long storeId) {
        log.info("开始获取商店账户审核数据业务。storeId={}", storeId);

        AccountAuditDetailDto accountAuditDetailDto = auditManager.getAccountAuditDetail(storeId);

        log.info("获取商店账户审核数据业务结束");
        return Result.success(accountAuditDetailDto);
    }

    /**
     * 获取商店老板审核数据接口
     * @param storeId 商店账户
     * @return 结果
     */
    @GetMapping("/boss/detail")
    public Result<BossAuditDetailDto> getBossAuditDetail(@RequestParam("storeId") Long storeId) {
        log.info("开始获取商店老板审核数据业务。storeId={}", storeId);

        BossAuditDetailDto bossAuditDetailDto = auditManager.getBossAuditDetail(storeId);

        log.info("获取商店老板审核数据业务结束");
        return Result.success(bossAuditDetailDto);
    }

}
